package com.burpee.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.burpee.ui.Choice;
import com.burpee.ui.Comments;

@Repository(value="commentsDao")
public class CommentsDaoImpl implements CommentsDao {

	SqlSessionTemplate sqlSessionTemplate;

	@Autowired
	public void setSqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
		this.sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory);
	}

	public List<Comments> list() {
		List<Comments> list=null;

		try {
			list = sqlSessionTemplate.selectList("commentslist");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return list;
	}

	public Comments view(Comments comments) {
		Comments commentsview=new Comments();

		try {
			commentsview = sqlSessionTemplate.selectOne("commentsview", comments);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return commentsview;
	}

	public int add(Comments comments) {
		
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.insert("commentsadd",comments);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	public int modify(Comments comments) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.update("commentsmodify",comments);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	public int remove(Comments comments) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.update("commentsremove",comments);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

}
